<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/common/inner-header.jspf"%>
<link rel="stylesheet" href="<%=request.getContextPath()%>/static/sys/user/css/reveal.css">	
<script type="text/javascript" src="<%=request.getContextPath()%>/static/sys/user/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/sys/user/js/jquery.reveal.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/sys/user/js/list-user.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/static/sys/user/css/user-list.css"/>
<title>用户列表</title>
</head>
<body>
		<div id="myModal" class="reveal-modal"">
			<form action="" id="myform2"  name ="myform2"  onsubmit="changeUserInfo();" method="post">
			<input type="button"style="position: absolute;top:0;right:0;height:28px; font-size: 25px;" value="X" onclick="closeBox()">
				<hr/>
				<div id="alterUserInfoInnerBox">
				</div>
				<input id="changeUserInfoSubmit" style="margin-left:180px;" type="submit" style="margin-left:40px;" value = "修改"/>　　　<input type="button" onclick ="closeBox()" value="取消"/>
			</form>
		</div>
<form id="myform1" name="myform1" action = "<%=request.getContextPath()%>/user/AllUserCommandServlet?command=splitList" method="post">
	用户名：<input name = "name" type="text" value = "${researchInfo.name }"></input>
	&nbsp;&nbsp;角色：<select name="roleName" class="roleName">
								<option value="">--</option>
								<c:forEach items="${researchInfo.roleList }"  var="role">
									<option value="${role}" <c:if test="${researchInfo.roleName == role}">selected=selected</c:if>>${role}</option>
								</c:forEach>
							</select>
							<span id="hideClass">
	&nbsp;&nbsp;班级：<select name="className">
								<option value="">--</option>
								<c:forEach items="${researchInfo.classList }"  var="selectClass">
									<option value="${selectClass}" <c:if test="${researchInfo.className == selectClass}">selected=selected</c:if>>${selectClass}</option>
								</c:forEach>
							</select>
							</span>
	&nbsp;&nbsp;状态<select name="state">
								<option value="">--</option>
								<option value="有效" <c:if test="${researchInfo.stateStr == '有效'}">selected=selected</c:if>>有效</option>
								<option value="无效" <c:if test="${researchInfo.stateStr == '无效'}">selected=selected</c:if>>无效</option>
							</select>
							<input type = "submit" value="查询" title="点击查询"></input>
</form>

<%--表格形式显示数据 --%>
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" height="19" valign="bottom"><div align="center"><img src="<%=request.getContextPath()%>/static/common/basic-page/images/tb.gif" width="14" height="14" /></div></td>
                <td width="94%" valign="bottom"><span class="STYLE1"> 管理人员基本信息列表</span></td>
              </tr>
            </table></td>
            <td><div align="right"><span class="STYLE1">
              <input type="checkbox" name="checkbox11" id="checkbox11" />
              全选      &nbsp;&nbsp;<a href="<%=request.getContextPath() %>/user/AllUserCommandServlet?command=toAddUser"><img src="<%=request.getContextPath()%>/static/common/basic-page/images/add.gif" width="10" height="10" /> 添加</a>   &nbsp; <img src="<%=request.getContextPath()%>/static/common/basic-page/images/del.gif" width="10" height="10" /> 删除    &nbsp;&nbsp;<img src="<%=request.getContextPath()%>/static/common/basic-page/images/edit.gif" width="10" height="10" /> 编辑   &nbsp;</span><span class="STYLE1"> &nbsp;</span></div></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    </td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
				<thead>
					<tr>
						<th width="4%" height="20" bgcolor="d3eaef" class="STYLE10">
						<div align="center">
							<input type="checkbox" name="checkbox" id="checkbox" />
						</div>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">序号</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">账号</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">用户名</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">性别</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">电话</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">邮箱</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">创建时间</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">用户角色</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">班级</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">状态</span></div></td>
						<td height="20" bgcolor="d3eaef" class=STYLE19><div align="center"><span class="STYLE10">备注</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">操作</span></div></td>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${pageModel.list}" var="user"  varStatus="num">
							<tr class="userListTr">
							<td height="20" bgcolor="#FFFFFF"><div align="center">
						          <input type="checkbox" name="checkbox4" id="checkbox4" />
						    </div></td>
							<td height="20" bgcolor="d3eaef" class="STYLE21" scope="row"> ${num.count+(pageModel.pageNo-1)*pageModel.pageSize} </td>
							<td height="20" bgcolor="d3eaef" class="STYLE21" id = "code${num.count}">${user.code }</td>
							<td id="name${num.count }" height="20" bgcolor="d3eaef" class="STYLE21">${user.name}</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${user.sexStr }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${user.phone }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${user.email }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21"><fmt:formatDate value="${user.createTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${user.roleName}</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${user.className}</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21" id="state${num.count }">${user.stateStr}</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${user.memo}</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21"><a href = "javascript:;"  onclick="getChangeUserInfo(${user.id})"  data-reveal-id="myModal">修改</a>|<a name="changeState${num.count }" id = "changeState${num.count }" href = "javascript:;" onclick="checkIsChange(${num.count},${user.id});">${user.reStateStr }</a>|<span id="reset${num.count }"><c:if test="${user.password !='123456'}"><a href="javascript:;" onclick="resetPassCheck(${num.count},${user.id});">重置密码</a></c:if><c:if test="${user.password =='123456'}">初始密码</c:if></span></td>
					</tr> 
				</c:forEach>
				<tr>
						<td colspan="12" align="right">
							<a href = "javascript:;" onclick="submitCondition(${pageModel.first});">首页</a>&nbsp;
							<a href = "javascript:;" onclick="submitCondition(${pageModel.pre});">上一页</a>&nbsp;
							第<select onchange="goPage(this)">
								<script>
									var pageNo = '${pageModel.pageNo}';
									var totalPage = '${pageModel.totalPage}';
									for (var i = 1; i <= totalPage; i++) {
										if (pageNo == i) {
											document.write('<option value="' + i + '" selected="selected">' + i + '</option>');
										} else {
											document.write('<option value="' + i + '">' + i + '</option>');
										}
									}
								</script>
							 </select>页
							,共${pageModel.totalPage}页&nbsp;
							<a href = "javascript:;" onclick="submitCondition(${pageModel.next});">下一页</a>&nbsp;
							<a href = "javascript:;" onclick="submitCondition(${pageModel.last});">尾页</a>&nbsp;
							共${pageModel.allRecords }条记录
						</td>
					</tr>
				</tbody>
			</table>
		</td>
	</tr>
</table>
</body>
<script type="text/javascript">
	var staticId = 0;
	function submitCondition(pageNo){
		document.myform1.action="<%=request.getContextPath()%>/user/AllUserCommandServlet?command=splitList&pageNo="+pageNo;
		document.myform1.submit();
	}
	
	/**
	 * 页面直接跳转
	 */
	function goPage(obj){
		submitCondition(obj.value);
	}
	/**
	*layer 提示重置密码
	*/
	function resetPassCheck(num,id){
		var name = $("#name"+num).html();
		layer.confirm('您确定要将'+name+'的密码重置为123456？', {
			  btn: ['确定','取消'] //按钮
			}, function(){
			  resetPass(num,id);
			  layer.msg('操作成功', {icon: 1});
			}, function(){
			});
	}
	/**
	* 重置密码
	*/
	function resetPass(num,id){
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    	document.getElementById("reset"+num).innerHTML=xmlhttp.responseText;
		 	}
		  }
		xmlhttp.open("POST",'<%=request.getContextPath()%>/user/AllUserCommandServlet',true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send('command=resetPass&id='+id);
	}
	
	function checkIsChange(num,id){
		var name = $("#name"+num).html();
		layer.confirm('您确定要更改'+name+'的状态？', {
			  btn: ['确定','取消'] //按钮
			}, function(){
			  loadXMLDoc(num,id);
			  layer.msg('操作成功', {icon: 1});
			}, function(){
			});
	}
	/*-----------------------
	  ajax异步修改用户状态
	 -----------------------*/
		function loadXMLDoc(num,id)
		{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
				var state = xmlhttp.responseText;
		    	document.getElementById("state"+num).innerHTML=state;
		    	if(state == '有效'){
		    		document.getElementById("changeState"+num).innerHTML="无效";
		   		}else{
		   			document.getElementById("changeState"+num).innerHTML="有效";
		    	}
		 	}
		  }
		xmlhttp.open("POST","<%=request.getContextPath()%>/user/AllUserCommandServlet",true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send('command=changeState&id='+id);
		}
		/*-----------------------
		 显示即将修改的信息
		------------------------- */
		function getChangeUserInfo(id){
			var xmlhttp;
			staticId=id;
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
			    {
					var user = eval('('+xmlhttp.responseText+')');
		 			var classList = eval(<%=request.getAttribute("classListJson")%>);
					setAlterBox(user,classList);
			 	}
			}
			xmlhttp.open("POST",'<%=request.getContextPath()%>/user/AllUserCommandServlet',true);
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			xmlhttp.send("command=getUserInfo&id="+id);
		} 

		
		/**
		 *  改变用户信息
		 */
		function changeUserInfo(id){
			
			var xmlhttp;
			var userStr = $("#myform2").serialize();
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
			    {
					var user = eval('('+xmlhttp.responseText+')');
		 			
			 	}
			}
			xmlhttp.open("POST",'<%=request.getContextPath()%>/user/AllUserCommandServlet?command=changeUserInfo',true);
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			xmlhttp.send("id="+staticId+"&"+userStr);
			
		}
</script>
</html>
